//
//  DAMessageDetailViewController.m
//  DAKnowledge
//
//  Created by DreamArts on 16/7/7.
//  Copyright © 2016年 lidongyang. All rights reserved.
//

#import "DAMessageDetailViewController.h"
#import "DAMessageDetailBackBookTimeLineView.h"
#import "DAMessageDetailTableViewCell.h"
#import "DAMessageDetailModel.h"
#import "DAReplyModel.h"
#import "DAMessageDetailBorrowBookTimeLineView.h"
#import "DAInputCommentView.h"
#import "DAMessageDetailFileUploadView.h"
#import "DAHomePageShowBookDetailViewController.h"
#import "DASearchBookDetailViewController.h"
#import "DAOtherPersonalViewController.h"
#import "DAWebFileViewController.h"

@interface DAMessageDetailViewController () <UITableViewDataSource, UITableViewDelegate, MessageDetailBackBookTimelineDelegate, MessageDetailBorrowBookTimelineDelegate, MessageDetailFileUploadDelegate>{
    
    UITableView *messageDetailTableView;
    NSMutableArray *dataArray;
    DAMessageDetailModel *messageDetailModel;
    NSString *timelineType;
    CGFloat headerHeight;
    DAMessageDetailBackBookTimeLineView *backTimelineView;
    DAMessageDetailBorrowBookTimeLineView *borrowTimelineView;
    DAMessageDetailFileUploadView *fileUploadView;
    DAInputCommentView *inputCommentView;
    DAHomePageShowBookDetailViewController *bookDetailView;
    UIView *grayView;
    //UIView *backView;
    NSString *replyTimeline;
    NSString *userName;
    NSMutableDictionary *replyDic;
    NSString *currentTime;
    BOOL isComment;
    CGFloat replyViewDrawFloat;
    CGPoint currentTableViewPoint;
    NSString *replyUserID;
    NSString *replyToUserName;
    NSIndexPath *selectIndexPath;
    BOOL isFirstCreat;
    NSInteger count;
    BOOL isShowingKeyboard;  // 键盘状态
}
@property (nonatomic, strong) UIView *backView;

@end

@implementation DAMessageDetailViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self creatTableView];
    [self creatInputView];
    [self creatBookDetailView];
    [messageDetailTableView.mj_header beginRefreshing];
   // [self addNotficationObserver];
    count = 0;
}
- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [self addNotficationObserver];
}
- (void)viewDidDisappear:(BOOL)animated{
    [super viewDidDisappear:animated];
    [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillShowNotification object:nil];
    [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillHideNotification object:nil];
    [[NSNotificationCenter defaultCenter] removeObserver:self name:@"MESSAGEDETAILISUSERID" object:nil];
}
- (void)dealloc{
    [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillShowNotification object:nil];
    [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillHideNotification object:nil];
    [[NSNotificationCenter defaultCenter] removeObserver:self name:@"MESSAGEDETAILISUSERID" object:nil];
}
#pragma mark - 添加通知
- (void)addNotficationObserver{
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(InputCommentViewKeyboardRiseUp:) name:UIKeyboardWillShowNotification object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(InputCommentViewKeyboardHiddenDown:) name:UIKeyboardWillHideNotification object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(sendUserID:) name:@"MESSAGEDETAILISUSERID" object:nil];
   // [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(turnMessageDetail) name:@"TURNMESSAGEDETAIL" object:nil];
}
#pragma mark - 数据准备
- (void)prepareData{
    NSString *url = DAReply_timelineURL;
    NSDictionary *dic = @{@"timelineID": self.timelineID};
    __weak typeof(self)weakSelf = self;
       [DADataHandel postURL:url parame:dic cookie:nil result:^(id result) {
           if ([result[@"result"] isKindOfClass:[NSDictionary class]]) {
               messageDetailModel = [DAMessageDetailModel returnModelWithDic:result[@"result"]];
               replyTimeline = messageDetailModel.timelineID;
               dataArray = [DAReplyModel returnModelInArrayWithDic:messageDetailModel.replyArray];
               timelineType = messageDetailModel.timelineType;
              // userName = messageDetailModel.userName;
               [self getUserInfo];
               CGFloat height = [weakSelf heightWithText:messageDetailModel.rateMessage Width:[UIScreen mainScreen].bounds.size.width - 120 Font:12];
               // 计算评价的高度
               if ([timelineType isEqualToString:@"2"]) {
                   headerHeight = 183 + height;
               }else{
                   headerHeight = 158;
               }
               [messageDetailTableView.mj_header endRefreshing];
               [messageDetailTableView reloadData];
               [weakSelf updateHeaderView];
               if (self.isShowNowMessage) {
                   NSIndexPath *indexPath = [NSIndexPath indexPathForRow:dataArray.count - 1 inSection:0];
                   [messageDetailTableView scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionBottom animated:YES];
                   self.isShowNowMessage = NO;
               }
               
           }else{
               // 异常处理  TODO
               NSLog(@"请求数据失败");
               if ([result[@"result"] isKindOfClass:[NSString class]] && [result[@"result"] isEqualToString:self.requestTimeOut]) {
                   [SVProgressHUD showErrorWithStatus:self.requestTimeOut];
               }
               if ([result[@"result"] isKindOfClass:[NSString class]] && [result[@"result"] isEqualToString:self.netIsNotAvailabel]) {
                   [SVProgressHUD showErrorWithStatus:self.netIsNotAvailabel];
               }
               if ([result[@"result"] isKindOfClass:[NSString class]] && [result[@"result"] isEqualToString:self.netWorkPortConnection]) {
                   [SVProgressHUD showErrorWithStatus:self.netWorkPortConnection];
               }
               else{
                   [SVProgressHUD showErrorWithStatus:self.requestFailed];
               }
               [messageDetailTableView.mj_header endRefreshing];
           }
//           [messageDetailTableView reloadData];
//           [weakSelf updateHeaderView];
       }];
}
#pragma mark - 发表评论的网络请求
- (void)postReplyMessage:(NSString *)message{
    NSString *url = DASendReplyMessageURL;
    if (isComment) {
        replyDic = [@{@"userID":self.userID,
                      @"replyTimeline": replyTimeline,
                      @"replyContent": message}mutableCopy];
    }else{
        replyDic = [@{@"userID": self.userID,
                      @"replyTimeline": replyTimeline,
                      @"replyUserID": replyUserID,
                      @"replyContent": message}mutableCopy];
    }
    __weak typeof(self)weakSelf = self;
    [DADataHandel postURL:url parame:replyDic cookie:nil result:^(id result) {
        if ([result[@"result"] isEqualToString:@"true"]) {
            NSLog(@"评论成功啦");
            currentTime = [weakSelf getDateNow];
            [replyDic setValue:currentTime forKey:@"replyDate"];
            if (isComment) {
                [replyDic setValue:userName forKey:@"replyUserName"];
            }else{
                [replyDic setValue:userName forKey:@"replyUserName"];
                [replyDic setValue:replyToUserName forKey:@"replyToName"];
                [replyDic setValue:self.userID forKey:@"replyUserID"];
            }
            DAReplyModel *replyModel = [DAReplyModel returnModelWithDic:replyDic];
            [dataArray addObject:replyModel];
            [messageDetailTableView reloadData];
            NSIndexPath *indexPath = [NSIndexPath indexPathForRow:dataArray.count - 1 inSection:0];
            [messageDetailTableView scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionBottom animated:YES];
        }else{
            NSLog(@"评论失败了");
            NSString *isFail = NSLocalizedString(@"isCommentFail", nil);
            [SVProgressHUD showErrorWithStatus:isFail];
        }
    }];
}
#pragma mark - 创建tableview头部 (归还类型的)
- (void)creatBackTypeHeaderView{
    backTimelineView = [[DAMessageDetailBackBookTimeLineView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, headerHeight)];
    backTimelineView.model = messageDetailModel;
    backTimelineView.delegate = self;
    //[self.view addSubview:backTimelineView];
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(clickTableViewHeaderView:)];
    [backTimelineView addGestureRecognizer:tap];
    
}
#pragma mark - 创建tableview头部 (借阅类型)
- (void)creatBorrowTypeHeaderView{
    borrowTimelineView = [[DAMessageDetailBorrowBookTimeLineView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, headerHeight)];
    borrowTimelineView.model = messageDetailModel;
    borrowTimelineView.delegate = self;
    //[self.view addSubview:borrowTimelineView];
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(clickTableViewHeaderView:)];
    [borrowTimelineView addGestureRecognizer:tap];
    
}
#pragma mark -创建tableView头部 (文件上传类型)
- (void)creatFileUploadView{
    fileUploadView = [[DAMessageDetailFileUploadView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 130)];
    fileUploadView.model = messageDetailModel;
    fileUploadView.delegate = self;
    //[self.view addSubview:fileUploadView];
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(clickTableViewHeaderView:)];
    [fileUploadView addGestureRecognizer:tap];
}
#pragma mark - 头部视图的手势方法 点击的时候 键盘如果弹起 就让键盘失去响应
- (void)clickTableViewHeaderView:(UITapGestureRecognizer *)tap{
    if (isShowingKeyboard) {
        [inputCommentView.sendTextView resignFirstResponder];
    }
}
#pragma mark - 创建tableView
- (void)creatTableView{
    messageDetailTableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height - 64) style:UITableViewStylePlain];
    messageDetailTableView.delegate = self;
    messageDetailTableView.dataSource = self;
    messageDetailTableView.tableFooterView = [UIView new];
    messageDetailTableView.backgroundColor = [UIColor colorWithHexString:backGroundColor];
    [self.view addSubview:messageDetailTableView];
    [self creatRefreshGifHeader];
}

#pragma mark - 创建 DAHomePageShowBookDetailViewController
- (void)creatBookDetailView{
    bookDetailView = [self.storyboard instantiateViewControllerWithIdentifier:@"BOOKDETAIL"];
    bookDetailView.view.frame = CGRectMake(20, 80, self.view.frame.size.width - 40, 400 * HEIGHTTOFIT5s);
    [[UIApplication sharedApplication].keyWindow addSubview:bookDetailView.view];
    bookDetailView.isSelectMessage = YES;
    bookDetailView.view.hidden = YES;
}
#pragma mark - 显示 DAHomePageShowBookDetailViewController
- (void)showBookDetailView{
    [[UIApplication sharedApplication].keyWindow bringSubviewToFront:bookDetailView.view];
    /** 添加动画*/
    [UIView beginAnimations:@"animation" context:nil];
    [UIView setAnimationDuration:0.5f];
    [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
    [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:bookDetailView.view cache:YES];
    [UIView commitAnimations];
    /** 消失手势*/
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(clickClose:)];
    [bookDetailView.closeImageBackView addGestureRecognizer:tap];
    /** bookDetailView的  bookImage 手势方法*/
    UITapGestureRecognizer *bookImageTap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(clickBookImage:)];
    bookDetailView.bookImage.userInteractionEnabled = YES;
    [bookDetailView.bookImage addGestureRecognizer:bookImageTap];
}

#pragma mark - 创建灰色蒙版
- (void)showGrayView{
    // 灰色蒙版
    grayView = [[UIView alloc]initWithFrame:[UIScreen mainScreen].bounds];
    grayView.backgroundColor = [UIColor colorWithWhite:0 alpha:0.5];
    [[UIApplication sharedApplication].keyWindow addSubview:grayView];
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(clickClose:)];
    [grayView addGestureRecognizer:tap];
}
#pragma mark - 创建输入框
- (void)creatInputView{
    inputCommentView = [[DAInputCommentView alloc]initWithFrame:CGRectMake(0, SCREENHEIGHT + 40, SCREENWIDTH, 40)];
    inputCommentView.sendTextView.scrollsToTop = NO;
    [self.view addSubview:inputCommentView];
    __weak typeof(self)weakSelf = self;
    [inputCommentView setContentSizeBlock:^(CGSize contentSize) {
        [weakSelf updateHeight:contentSize];
    }];
    [inputCommentView setReplyAddBlock:^(NSString *replyText, NSInteger inputTag) {
        [weakSelf sendMessageComment:replyText];
    }];
}
#pragma mark - 创建背景透明的view
- (void)creatBackView{
    self.backView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREENWIDTH, SCREENHEIGHT)];
    self.backView.backgroundColor = [UIColor clearColor];
    [self.view addSubview:self.backView];
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(clickBackView)];
    [self.backView addGestureRecognizer:tap];
}
#pragma mark - 根据数据创建哪种类型的头部
- (void)updateHeaderView{
    if ([timelineType isEqualToString:@"2"]) {
        [self creatBackTypeHeaderView];
        messageDetailTableView.tableHeaderView = backTimelineView;
    }else if([timelineType isEqualToString:@"1"]){
        [self creatBorrowTypeHeaderView];
        messageDetailTableView.tableHeaderView = borrowTimelineView;
    } else{
        [self creatFileUploadView];
        messageDetailTableView.tableHeaderView = fileUploadView;
    }
}
#pragma mark - 创建tableView的头部动态图片
- (void)creatRefreshGifHeader{
    // 刷新头部
    MJRefreshGifHeader *header =[MJRefreshGifHeader headerWithRefreshingTarget:self refreshingAction:@selector(refreshData)];
    NSMutableArray *refreshImages = [[NSMutableArray alloc] init];
    for (NSUInteger i = 1; i<=21; i++) {
        UIImage *image = [UIImage imageNamed:[NSString stringWithFormat:@"page%ld@3x", (unsigned long)i]];
        [refreshImages addObject:image];
    }
    NSMutableArray *normalImages = [[NSMutableArray alloc] init];
    for (NSUInteger i = 1; i<=21; i++) {
        UIImage *image = [UIImage imageNamed:[NSString stringWithFormat:@"stay%ld@3x", (unsigned long)i]];
        [normalImages addObject:image];
    }
    UIImage *image = [UIImage imageNamed:@"stay21@3x"];
    [normalImages insertObject:image atIndex:0];
    [header setImages:refreshImages duration:0.5 forState:MJRefreshStateRefreshing];
    [header setImages:normalImages forState:MJRefreshStateIdle];
    [header setImages:refreshImages duration:0.5 forState:MJRefreshStatePulling];
    header.lastUpdatedTimeLabel.hidden= YES;//如果不隐藏这个会默认 图片在最左边不是在中间
    header.stateLabel.hidden = YES;
    messageDetailTableView.mj_header = header;
}
#pragma mark - 刷新数据
- (void)refreshData{
    [self prepareData];
}
#pragma mark - tableview dataSource deleagte
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return dataArray.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    static NSString *idetifier = @"MessafeDetailCell";
    DAMessageDetailTableViewCell *detailCell = [tableView dequeueReusableCellWithIdentifier:idetifier];
    if (detailCell == nil) {
        detailCell = [[DAMessageDetailTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:idetifier];
    }
    detailCell.replyModel = [dataArray objectAtIndex:indexPath.row];
    return detailCell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    DAReplyModel *replModel = [dataArray objectAtIndex:indexPath.row];
    CGFloat height = [self heightWithText:replModel.replyContent Width:[UIScreen mainScreen].bounds.size.width - 40 Font:12];
    return 56 + height;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    DAMessageDetailTableViewCell *detailCell = [tableView cellForRowAtIndexPath:indexPath];
    replyViewDrawFloat = [detailCell convertRect:detailCell.bounds toView:self.view.window].origin.y + detailCell.frame.size.height;
    isComment = NO;
    replyUserID = [[dataArray objectAtIndex:indexPath.row] replyUserID];
    selectIndexPath = indexPath;
    replyToUserName = [[dataArray objectAtIndex:indexPath.row] replyUserName];
    // 发送通知 更改placeHolder
     [[NSNotificationCenter defaultCenter] postNotificationName:@"CHANGEPLACEHOLDER" object:replyToUserName];
    // 判断是否是自己评论的
    if (![replyUserID isEqualToString:self.userID] && replyUserID != nil) {
        // 让输入框成为第一响应者
        count = 0;
        [inputCommentView.sendTextView becomeFirstResponder];
    }
    // 点击cell 的时候 如果键盘是弹起状态 ,点击的时候 就需要让输入框失去响应
    if (isShowingKeyboard) {
        [inputCommentView.sendTextView resignFirstResponder];
    }
    
}

- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
   
}

- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView{
    // 如果键盘状态是弹起的状态 滚动的时候失去响应
    if (isShowingKeyboard) {
        [inputCommentView.sendTextView resignFirstResponder];
    }
}

/**  方法区*/
#pragma mark - 点击背景透明view的点击方法
- (void)clickBackView{
    [inputCommentView.sendTextView resignFirstResponder];
    [self.backView removeFromSuperview];
}
#pragma amrk - 输入框的方法
// 键盘弹起
- (void)InputCommentViewKeyboardRiseUp:(NSNotification *)notif{
    count++;
    CGRect lastFrame = [[[notif userInfo] objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue];
    CGRect frame = [[[notif userInfo]objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue];
    __weak typeof(self)weakSelf = self;
    [UIView animateWithDuration:0.2 animations:^{
        inputCommentView.frame = CGRectMake(0, [UIScreen mainScreen].bounds.size.height - frame.size.height - 40 - 64, self.view.frame.size.width, 40);
        NSLog(@"%@", inputCommentView.placeHolder.text);
        CGRect commentViewFrame = inputCommentView.frame;
        CGPoint point = messageDetailTableView.contentOffset;
        currentTableViewPoint = point;
        if (isComment) {
        }else{
            if (count == 1) {
                point.y -= (commentViewFrame.origin.y + 64 - replyViewDrawFloat);
                messageDetailTableView.contentOffset = point;
            }else{
                 point.y = point.y + lastFrame.origin.y - frame.origin.y;
                 messageDetailTableView.contentOffset = point;
            }
            
        }
    } completion:^(BOOL finished) {
        // 键盘弹起之后 创建透明的背景view
        if (count == 1) {
            // [weakSelf creatBackView];
            [weakSelf.view bringSubviewToFront:inputCommentView];
            // 标记键盘弹起状态
            isShowingKeyboard = YES;
            
        }
    }];
}
// 键盘回落
- (void)InputCommentViewKeyboardHiddenDown:(NSNotification *)notif{
    
    [UIView animateWithDuration:0.2 animations:^{
        inputCommentView.frame = CGRectMake(0, [UIScreen mainScreen].bounds.size.height + 40, [UIScreen mainScreen].bounds.size.width, 40);
        if (isComment) {
            
        }else{
//            if ([UIScreen mainScreen].bounds.size.height == 736) {
//                if (selectIndexPath.row <= 2) {
//                    messageDetailTableView.contentOffset = currentTableViewPoint;
//                }
//            }else{
//                if (selectIndexPath.row == 0 || selectIndexPath.row == 1 || selectIndexPath.row == dataArray.count - 1) {
//                    messageDetailTableView.contentOffset = currentTableViewPoint;
//                }
//            }
            
            messageDetailTableView.contentOffset = currentTableViewPoint;
            
        }
    } completion:^(BOOL finished) {
        [self.backView removeFromSuperview];
        inputCommentView.sendTextView.text = nil;
        // 标记键盘回落状态
        isShowingKeyboard = NO;
    }];
}
// 通知方法
- (void)sendUserID:(NSNotification *)not{
    bookDetailView.view.hidden = YES;
    [grayView removeFromSuperview];
    [self turnPersonal:not.object];
}
#pragma makr  协议方法区
// 点击backBook 的评论
- (void)clickMessageDetailBackBookComment{
    NSLog(@"back评论");
    NSString *comment = NSLocalizedString(@"comment", nil);
    inputCommentView.placeHolder.text = comment;
    isComment = YES;
    count = 0;
    [inputCommentView.sendTextView becomeFirstResponder];
}

- (void)clickMessageDetailBackBookImageWidthID:(NSString *)bookID{
    bookDetailView.bookID = bookID;
    [bookDetailView prepareData];
    [self showGrayView];
    [self showBookDetailView];
}

- (void)clickMessageDetailBackBookUserFaceWithUserID:(NSString *)userID{
    [self turnPersonal:userID];
}
// 点击borrowBook 的评论
- (void)clickMessageDetailBorrowBookComment{
    NSLog(@"borrow评论");
    isComment = YES;
    count = 0;
    NSString *comment = NSLocalizedString(@"comment", nil);
    inputCommentView.placeHolder.text = comment;
    [inputCommentView.sendTextView becomeFirstResponder];
}
- (void)clickMessageDetailBorrowImageWithID:(NSString *)bookID{
    bookDetailView.bookID = bookID;
    [bookDetailView prepareData];
    [self showGrayView];
    [self showBookDetailView];
}

- (void)clickMessageDetailBorrowUserFaceWithUserID:(NSString *)userID{
    [self turnPersonal:userID];
}

// 点击 fileUpload 的评论
- (void)clickMessageDetailFileUpload{
    NSLog(@"fileUpload的评论");
    isComment = YES;
    count = 0;
    NSString *comment = NSLocalizedString(@"comment", nil);
    inputCommentView.placeHolder.text = comment;
    [inputCommentView.sendTextView becomeFirstResponder];
}

- (void)openFileWithUrl:(DAMessageDetailModel *)model{
    //文件保存路径
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDirectory = [paths objectAtIndex:0];
    NSString *filePath = [NSString stringWithFormat:@"%@/%@.%@", documentsDirectory, model.timelinefoldername,model.timelinefileExtend];
    //NSLog(@"文件保存路径 %@",documentsDirectory);
    DAWebFileViewController *webFile = [[DAWebFileViewController alloc]init];
    webFile.fileUrl = filePath;
    webFile.fileID = model.fileID;
    webFile.filefolderName = model.fileFolderName;
    webFile.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:webFile animated:YES];
    
}

- (void)clickMessageDetailFileUploadUserFaceWithUserID:(NSString *)userID{
    [self turnPersonal:userID];
}
#pragma mark - 发表评论触发的方法
- (void)sendMessageComment:(NSString *)str{
    [self postReplyMessage:str];
    [inputCommentView.sendTextView resignFirstResponder];
}
// 根据文字多少 更新replyView的高度约束
- (void)updateHeight:(CGSize)contenSize{
    CGFloat contentSizeHeight = contenSize.height;
    //设置最大不能超过 100 (根据需要调整)
    if (contenSize.height > 100) {
        contentSizeHeight = 100;
    }
    float height = contentSizeHeight + 10;
    CGRect frame = inputCommentView.frame;
    frame.origin.y -= height - frame.size.height;
    frame.size.height = height;
    inputCommentView.frame = frame;
}
#pragma mark - 获取当前系统时间
- (NSString *)getDateNow{
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc]init];
    [dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
    NSString *currentDateStr = [dateFormatter stringFromDate:[NSDate date]];
    return currentDateStr;
}
#pragma mark - 点击ShowBookDetail BookImage
- (void)clickBookImage:(UITapGestureRecognizer *)tap{
    // 跳转到图书详情页面
    UIStoryboard *story = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
    DASearchBookDetailViewController * detailVC = [story instantiateViewControllerWithIdentifier:@"SEARCHBOOKDETAIL"];
    detailVC.bookID = bookDetailView.bookID;
    [self clickClose:nil];
    detailVC.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:detailVC animated:YES];
}

- (void)getUserInfo{
    userName = [self readLocalTheUserInfoData];
}

#pragma mark - BookDetailView Close Image Func
- (void)clickClose:(UITapGestureRecognizer *)tap{
    bookDetailView.view.hidden = YES;
    [grayView removeFromSuperview];
}

#pragma mark - 跳转到其他个人页面
- (void)turnPersonal:(NSString *)userID{
    DAOtherPersonalViewController *otherPeosonal = [self.storyboard instantiateViewControllerWithIdentifier:@"OTHERPERSONAL"];
    otherPeosonal.hidesBottomBarWhenPushed = YES;
    otherPeosonal.otherUserID = userID;
    [self.navigationController pushViewController:otherPeosonal animated:YES];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
    NSLog(@"DAMessageDetailViewController is Warning");
}




/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
